import 'package:flutter/material.dart';
import 'package:online_study/classify/classify_page.dart';
import 'package:online_study/home/home_page.dart';
import 'package:online_study/mine/my_page.dart';
import 'package:online_study/theme/size.dart';

class MyBottomNavigationWidget extends StatefulWidget {
  @override
  _MyBottomNavigationWidgetState createState() => _MyBottomNavigationWidgetState();
}

class _MyBottomNavigationWidgetState extends State<MyBottomNavigationWidget> {
  int _currentIndex=0;
  final _BottomNavigationActiveColor=Colors.blue;
  final _BottomNavigationColor=Colors.black;
  var _controller =PageController(initialPage: 0);
  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: [
          HomePage(),
          ClassifyPage(),
          MyPage()
        ],
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index){
          _controller.jumpToPage(index);
          setState(() {
            _currentIndex=index;
          });
        },
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
              icon: Icon(const IconData(0xe723, fontFamily: 'IconFonts'),
                  size: ThemeSize.height20,
                  color: _currentIndex == 0
                      ? _BottomNavigationActiveColor
                      : _BottomNavigationColor),
            label: "首页"
          ),
          BottomNavigationBarItem(
              icon: Icon(
                  const IconData(0xe61d, fontFamily: 'IconFonts'),
                  size: ThemeSize.height20,
                  color: _currentIndex == 1
                      ? _BottomNavigationActiveColor
                      : _BottomNavigationColor),
              label: "分类"
          ),
          BottomNavigationBarItem(
              icon: Icon(
                  const IconData(0xe61a, fontFamily: 'IconFonts'),
                  size: ThemeSize.height20,
                  color: _currentIndex == 2
                      ? _BottomNavigationActiveColor
                      : _BottomNavigationColor),
              label: "我的"
          ),
        ],
      ),
    );
  }
}
